package com.li.algorithm.leetcode.hot100;

import java.util.HashSet;

public class Test8 {

    public int lengthOfLongestSubstring(String s) {
        int max = 0;
        int i = 0, j = 0;
        HashSet<Character> set = new HashSet<>();
        //TODO: 分为起点和终点
        //TODO: 如果不排斥，移动终点
        //TODO: 如果排斥，移动起点
        //TODO: 每次出现排斥，记录当前长度
        while (j < s.length() && i <= j) {
            char c = s.charAt(j);
            if (!set.contains(c)) {
                max = Math.max(max, j - i +1);
                set.add(c);
                j++;
            } else {
                max = Math.max(max, j - i);
                set.remove(s.charAt(i));
                i++;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Test8 test8 = new Test8();
        System.out.println(test8.lengthOfLongestSubstring(" "));
    }
}


